package sg.edu.nus.iss.billing.vo.account;

import java.util.List;

import sg.edu.nus.iss.billing.common.DbUtil;
import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.common.exception.InvalidParamsException;
import sg.edu.nus.iss.billing.vo.common.IDbSerialisable;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;

public class AccountVO implements IDbSerialisable {

	private String accountNo;
	private String nric;
	private String status;
	private List<SubscriptionVO> listSubscriptionVO;
	
	
	public AccountVO() {
		setAccountNo(Util.Default_NULL);
		setNric(Util.Default_NULL);
		setStatus(Util.ACCOUNT_STATUS_INACTIVE);
	}
	
	public AccountVO(String accountNo) {
		super();
		this.accountNo = accountNo;
	}
	
	/**
	 * @return the accountNo
	 */
	public String getAccountNo() {
		return accountNo;
	}
	/**
	 * @param accountNo the accountNo to set
	 */
	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	/**
	 * @return the billDetailList
	 */
	public double getOutStandingBalance() {
		return 0.0;
	}

	public String getNric() {
		return nric;
	}

	public void setNric(String nric) {
		this.nric = nric;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public List<SubscriptionVO> getListSubscriptionVO() {
		return listSubscriptionVO;
	}

	public void setListSubscriptionVO(List<SubscriptionVO> listSubscriptionVO) {
		this.listSubscriptionVO = listSubscriptionVO;
	}

	@Override
	public void setParameters(String serialisedEntry)
			throws InvalidParamsException {
		//AA-0000-00-99^S1234567A^ACTIVE
		String[] tokens =  serialisedEntry.split(java.util.regex.Pattern.quote(DbUtil.DELIMITER));
		if (tokens.length != 3) {
			throw new InvalidParamsException("Expected 3 parameters, received " + tokens.length);
		} else {
			setAccountNo(tokens[0]);
			setNric(tokens[1]);
			setStatus(tokens[2]);
		}
	}

	@Override
	public String serialised() {
		StringBuilder sb = new StringBuilder();
		sb.append(getAccountNo());
		sb.append(DbUtil.DELIMITER);
		sb.append(getNric());
		sb.append(DbUtil.DELIMITER);
		sb.append(getStatus());
		return sb.toString();
	}
}
